package dao;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class DBUtil {
	private static String driver;
	private static String url;
	private static String user;
	private static String password;
	private static Connection conn;

	static {
		Properties ppt = new Properties();
		InputStream in = DBUtil.class.getResourceAsStream("/dbo.properties");
		try {
			ppt.load(in);
			driver = ppt.getProperty("driver");
			url = ppt.getProperty("url");
			user = ppt.getProperty("user");
			password = ppt.getProperty("password");
			Class.forName(driver);
			conn = DriverManager.getConnection(url, user, password);

		} catch (IOException e) {
			System.out.println("文件加载失败");
		} catch (ClassNotFoundException e) {
			System.out.println("驱动加载失败");
		} catch (SQLException e) {
			System.out.println("数据库连接失败");
		}

	}

	public static Connection getConn() {
		return conn;
	}
}
